package net.qiyuesuo;

import javax.servlet.MultipartConfigElement;
import javax.servlet.annotation.MultipartConfig;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;

import net.qiyuesuo.controller.DeleteFileServlet;
import net.qiyuesuo.controller.DownLoadFileServlet;
import net.qiyuesuo.controller.GetFileInfoServlet;
import net.qiyuesuo.controller.UploadFileServlet;

/**
 * 使用内置 Jetty 容器，启动web服务
 * @author Administrator
 *
 */
@MultipartConfig
public class HttpService {
	
	public static void main(String[] args) throws Exception {
		Server server = new Server(8080);
		
		ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
		context.setContextPath("/");

		ServletHolder fileUploadServletHolder = new ServletHolder(new UploadFileServlet());
		fileUploadServletHolder.getRegistration().setMultipartConfig(new MultipartConfigElement("", 1048576, 1048576, 262144));
		context.addServlet(fileUploadServletHolder, "/file/upload");
		context.addServlet(DownLoadFileServlet.class, "/file/download");
		context.addServlet(GetFileInfoServlet.class, "/file/getInfo");
		context.addServlet(DeleteFileServlet.class, "/file/delete");
		
		server.setHandler(context);
		server.start();
		server.join();
	}
	
}
